import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout *///页面整体布局组件
import Layout from '@/layout'

/* Router Modules */
import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'

/**
 * 定义组件名称和组件对象的map对象
*/
export const componentMap = {
  'layout': require('@/layout').default,
  'redirect_index': () => import('@/views/redirect/index').then(m=>m.default),
  'login_index': () => import('@/views/login/index').then(m=>m.default),
  'login_auth_redirect': () => import('@/views/login/auth-redirect').then(m=>m.default),
  'error_page_404': () => import('@/views/error-page/404').then(m=>m.default),
  'error_page_401': () => import('@/views/error-page/401').then(m=>m.default),
  'dashboard_index': () => import('@/views/dashboard/index').then(m=>m.default),
  'documentation_index': () => import('@/views/documentation/index').then(m=>m.default),
  'guide_index': () => import('@/views/guide/index').then(m=>m.default),
  'profile_index': () => import('@/views/profile/index').then(m=>m.default),
  'permission_menu': () => import('@/views/permission/menu').then(m=>m.default),
  'permission_resource': () => import('@/views/permission/permResource').then(m=>m.default),
  'permission_role': () => import('@/views/permission/role').then(m=>m.default),
  'user_role': () => import('@/views/permission/user').then(m=>m.default),
  'icons_index': () => import('@/views/icons/index').then(m=>m.default),
  //教师角色，我的指导学生界面
  'my_guide': () => import('@/views/guide/index').then(m=>m.default),
  //实训单位查询
  'all_company': () => import('@/views/company/allCompany').then(m=>m.default),
  //我的实训单位
  'my_company': () => import('@/views/company/myCompany').then(m=>m.default),
  //周月报查询
  'all_report': () => import('@/views/report/allReport').then(m=>m.default),
  //我的周月报
  'my_report': () => import('@/views/report/myReport').then(m=>m.default),
  //成绩查询
  'all_result': () => import('@/views/result/allResult').then(m=>m.default),
  //我的成绩
  'my_result': () => import('@/views/result/myResult').then(m=>m.default),
  //我指导的学生
  'my_tutor': () => import('@/views/tutor/myTutor').then(m=>m.default),
  //系统设置
  'setting': () => import('@/views/setting/index').then(m=>m.default),
  //新增实训单位
  'add_company': () => import('@/views/company/addCompany').then(m=>m.default),
  //新增报告
  'add_report': () => import('@/views/report/addReport').then(m=>m.default),
  //实训单位审核
  'verify_company': () => import('@/views/company/verifyCompany').then(m=>m.default),
  //报告审核
  'verify_report': () => import('@/views/report/verifyReport').then(m=>m.default),
  //所有学生分配
  'all_tutor': () => import('@/views/tutor/allTutor').then(m=>m.default),
  //通知管理
  'all_notice': () => import('@/views/notify/allNotice').then(m=>m.default),
  //学生实训管理
  'student_company': () => import('@/views/company/studentCompany').then(m=>m.default),
  //学生信息审核
  'verify_student_company': () => import('@/views/company/verifyStudentCompany').then(m=>m.default),
}

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   设置菜单是否隐藏（不显示在左边菜单，缺省false）
 * alwaysShow: true               设置在一级菜单上，是否总是显示，true表示总是显示
 *                                如果为false，一级菜单只会在有多个子菜单情况下才显示
 * redirect: noRedirect           如果设置成noRedirect，面包屑不会重定向
 * name:'router-name'             路由名称，必须设置，且唯一
 * meta : {
    roles: ['admin','editor']    允许路由的角色列表
    title: 'title'               显示在左边导航栏和面包屑上的名称
    icon: 'svg-name'/'el-icon-x' 图标名称
    noCache: true                页面是否不要缓存，缺省为false
    affix: true                  标签页面是否总是显示（不能关闭）
    breadcrumb: false            缺省true，是否以面包屑显示页面
    activeMenu: '/example/list'  在左边菜单上高亮显示
  }
 */


/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 * 基本路由表，所有用户都可以访问的路由表
 */
export const constantRoutes = [
  {
    path: "*",
    redirect: "/404"
},
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   children: [
  //     {
  //       path: 'dashboard',
  //       component: () => import('@/views/dashboard/index'),
  //       name: 'Dashboard',
  //       meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
  //     }
  //   ]
  // },
  {
    path: '/',//路由访问路径
    component: Layout,//整体界面模板
    redirect: '/index',//重定向路径
    children: [
      {
        path: 'index',//访问路径
        component: () => import('@/views/documentation/index'),//页面内容模板
        name: '首页',//模板名称
        meta: { title: '首页', //菜单标题
                icon: 'documentation',//菜单图标
                noCache: true,//页面是否不要缓存，缺省为false
                affix: false, //标签页面是否总是显示（不能关闭）
                
              }
      }
    ]
  },
  {
    path: '/guide',
    component: Layout,
    redirect: '/guide/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/guide/index'),
        name: '通知公告',
        meta: { title: '通知公告', icon: 'guide', noCache: true }
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: '个人信息',
        meta: { title: '个人信息', icon: 'user', noCache: true }
      }
    ]
  },
  //消息中心模块
  {
    path: '/notify',
    component: Layout,
    redirect: '/notify/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/notify/index'),
        name: '消息中心',
        meta: { title: '消息中心', icon: 'user', noCache: true }
      }
    ]
  },
  //实训单位详情
  {
    path: '/companyDetail',
    component: Layout,
    redirect: '/companyDetail/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/company/companyDetail'),
        name: '新训单位详情',
        meta: { title: '实训单位详情', icon: 'user', noCache: true }
      }
    ]
  },
  //聊天页面
  {
    path: '/notify/chat',
    component: Layout,
    redirect: '/notify/chat/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/notify/chat'),
        name: '聊天',
        meta: { title: '聊天', icon: 'user', noCache: true }
      }
    ]
  },
  //报告详情页
  {
    path: '/reportDetail',
    component: Layout,
    redirect: '/reportDetail/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/report/reportDetail'),
        name: '报告详情',
        meta: { title: '报告详情', icon: 'user', noCache: true }
      }
    ]
  },
   //指导教师分配的学生详情页
   {
    path: '/tutorDetail',
    component: Layout,
    redirect: '/tutorDetail/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/tutor/tutorDetail'),
        name: '分配详情',
        meta: { title: '分配详情', icon: 'user', noCache: true }
      }
    ]
  },
   //新建通知公告界面
   {
    path: '/addNotice',
    component: Layout,
    redirect: '/addNotice/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/notify/addNotice'),
        name: '新建通知',
        meta: { title: '新建通知', icon: 'user', noCache: true }
      }
    ]
  },
   //通知公告详情界面
   {
    path: '/noticeDetail',
    component: Layout,
    redirect: '/noticeDetail/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/notify/noticeDetail'),
        name: '通知详情',
        meta: { title: '通知详情', icon: 'user', noCache: true }
      }
    ]
  },
     //通知公告详情界面
     {
      path: '/editNotice',
      component: Layout,
      redirect: '/editNotice/index',
      hidden: true,
      children: [
        {
          path: 'index',
          component: () => import('@/views/notify/editNotice'),
          name: '修改通知',
          meta: { title: '修改通知', icon: 'user', noCache: true }
        }
      ]
    },
       //用户主页
       {
        path: '/userIndex',
        component: Layout,
        redirect: '/userIndex/index',
        hidden: true,
        children: [
          {
            path: 'index',
            component: () => import('@/views/user/userIndex'),
            name: '用户主页',
            meta: { title: '用户主页', icon: 'user', noCache: true }
          }
        ]
      },
      //实训单位审核时查看的实训单位详情界面
      {
        path: '/verifyCompanyDetail',
        component: Layout,
        redirect: '/verifyCompanyDetail/index',
        hidden: true,
        children: [
          {
            path: 'index',
            component: () => import('@/views/company/verifyCompanyDetail'),
            name: '实训单位审核详情',
            meta: { title: '实训单位审核详情', icon: 'user', noCache: true }
          }
        ]
      },
      //报告审核时查看的报告详情界面
      {
        path: '/verifyReportDetail',
        component: Layout,
        redirect: '/verifyReportDetail/index',
        hidden: true,
        children: [
          {
            path: 'index',
            component: () => import('@/views/report/verifyReportDetail'),
            name: '报告审核详情',
            meta: { title: '报告审核详情', icon: 'user', noCache: true }
          }
        ]
      },
      //实训单位提交历史
      {
        path: '/addCompanyHistory',
        component: Layout,
        redirect: '/addCompanyHistory/index',
        hidden: true,
        children: [
          {
            path: 'index',
            component: () => import('@/views/company/addCompanyHistory'),
            name: '提交记录',
            meta: { title: '提交记录', icon: 'user', noCache: true }
          }
        ]
      },
      //重新提交实训单位审核界面
      {
        path: '/editCompany',
        component: Layout,
        redirect: '/editCompany/index',
        hidden: true,
        children: [
          {
            path: 'index',
            component: () => import('@/views/company/editCompany'),
            name: '重新提交',
            meta: { title: '重新提交', icon: 'user', noCache: true }
          }
        ]
      },
      //修改报告界面
      {
        path: '/editReport',
        component: Layout,
        redirect: '/editReport/index',
        hidden: true,
        children: [
          {
            path: 'index',
            component: () => import('@/views/report/editReport'),
            name: '修改报告',
            meta: { title: '修改报告', icon: 'user', noCache: true }
          }
        ]
      }

]


const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
